/**
 * config.js 配置
 * https://github.com/vuejs/vuepress/blob/master/packages/docs/docs/.vuepress/config.js
 *
 *
 * 采用 和 vue 官网的搜索，这个需要 域名
 * https://www.vuepress.cn/zh/theme/default-theme-config.html#algolia-%E6%90%9C%E7%B4%A2
 */

// const path = require('path')
const vuePressSlide = require('./_slide')

const GitHubUrl = 'https://gitee.com/srxboys/rxios-questions'
const KEYS = ['ios', 'object-c', 'swift', '面试题', '笔试题']
const PRESS_DESC = KEYS.join('|')
const META_DESC = KEYS.join('，')
const META_KEYWORDS = KEYS.join(',')

const NAV_TEST_TITLE = '-----'

const NODE_ENV = process.env.NODE_EN
const ROOT_BASE = '/rxios-questions/' // 项目名 in GitHub/Gitee

// const ALIAS_IMG = ROOT_BASE.slice(0, ROOT_BASE.length - 1)

// 百度统计 key -> https://tongji.baidu.com/
const BaiDuTJKey = '2dc091ada8eed930d7a48b1b6523ee7c' // **需要修改**

module.exports = {
  // 环境变量(对象式) https://vuepress.vuejs.org/zh/plugin/option-api.html#define
  // 必须是 JSON.stringify(xx)
  define: {
    // SW_NODE_ENV: development production
    SW_NODE_ENV: JSON.stringify(NODE_ENV),
  },
  // https://vuepress.vuejs.org/zh/plugin/option-api.html#alias
  // 默认只能是 node_modules/，不能实现我们想要的
  // 使用: [图片](~@alias/xx.png)
  // alias: {
  //   'assets': JSON.stringify(ALIAS_IMG)
  // },
  // alias 图片另一种用法 https://vuepress.vuejs.org/zh/guide/assets.html#%E5%9F%BA%E7%A1%80%E8%B7%AF%E5%BE%84
  // ./node_modules/@vuepress/core/lib/client/app.js   line: 53
  /*
    Vue.prototype.$withBase = function (path) {
      const base = this.$site.base // -> this
      if (path.charAt(0) === '/') {
        return base + path.slice(1)
      } else {
        return path
      }
    }
  */

  title: 'IQ',
  description: PRESS_DESC, // 百度搜索 seo

  // 部署站点的基础路径 https://vuepress.vuejs.org/zh/config/#base
  base: ROOT_BASE, // 项目名 in GitHub/Gitee

  head: [
    // pwa https://vuepress.vuejs.org/zh/plugin/official/plugin-pwa.html#%E4%BD%BF%E7%94%A8

    // icons
    ['link', { rel: 'icon', href: `/logo.png` }],
    ['link', { rel: 'manifest', href: '/manifest.json' }],
    ['link', { rel: 'apple-touch-icon', href: '/icons/apple-touch-icon-152x152.png' }],
    ['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
    ['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],

    // html
    ['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
    ['meta', { name: 'theme-color', content: '#3eaf7c' }],
    ['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
    ['meta', { name: 'msapplication-TileColor', content: '#000000' }],

    // seo
    ['meta', { name: 'description', content: META_DESC }],
    ['meta', { name: 'keywords', content: META_KEYWORDS }], // 权重不太高，但是只要有轻重我们也要利用。

    // 数据统计 - 参考: https://blog.csdn.net/lovefive5/article/details/102466820
    ['script', {type: 'text/javascript'}, `
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?` + BaiDuTJKey + `";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
    `]
  ],

  markdown: {
    lineNumbers: true,
  },

  plugins: [
    // 置顶按钮
    ['@vuepress/back-to-top', true],
    // 更新时间插件 https://www.vuepress.cn/zh/plugin/official/plugin-last-updated.html
    ['@vuepress/last-updated'],
    // 缩放图像
    ['@vuepress/medium-zoom', {
      options: {
        margin: 16
      }
    }],
    // 刷新
    ['@vuepress/pwa', {
      serviceWorker: true,
      // updatePopup: true,
      updatePopup: {
        '/': {
          message: "发现有新内容可用",
          buttonText: "刷新"
        },
      }
    }],
  ],

  themeConfig: {
    logo: '/logo.png',

    // 假定是 GitHub. 同时也可以是一个完整的 GitLab URL
    repo: GitHubUrl,
    repoLabel: 'Gitee',
    docsDir: 'docsmd',
    // // 假如文档放在一个特定的分支下：
    docsBranch: 'master',
    editLinks: true,
    // // // 默认为 "Edit this page"
    editLinkText: '帮助改善此页面！',
    // 不显示搜索框
    // search: false,
    // [配合]更新时间插件 vuepress/last-updated
    lastUpdated: '上次更新', // string | boolean
    nav: [
      { text: '指南', link: '/guide/' },
      { text: 'Object-C', link: '/oc/' },
      { text: 'Swift', link: '/swift/' },
      { text: '文章', link: '/article/' },
      { text: '跨平台', link: '/cross-platform/' },
      { text: '面试题', link: '/iq/' },
      {
        text: '开发',
        ariaLabel: 'Language Menu',
        items: [
          {
            text: 'iOS', items: [
              { text: 'Object-C', link: '/oc/' },
              { text: 'Swift', link: '/swift/' },
              { text: NAV_TEST_TITLE, link: '/#' },
              { text: 'Library', link: '/library/' },
              { text: 'Framework', link: '/framework/' },
            ]
          },
          {
            text: 'native', items: [
              { text: 'react-native', link: '/cross-platform/native/rn' },
              { text: 'Flutter', link: '/cross-platform/native/flutter' },
              { text: 'Weex', link: '/cross-platform/native/weex' },
              { text: NAV_TEST_TITLE, link: '/#' },
              { text: 'Cordova', link: '/' },
              { text: 'uni-app', link: '/' },
              { text: 'Taro', link: '/' },
            ]
          },
          {
            text: 'Web / H5', items: [
              { text: 'Vue', link: '/' },
              { text: 'React', link: '/' },
              { text: 'Angular', link: '/' },
              { text: NAV_TEST_TITLE, link: '/#' },
              { text: 'Bulma', link: '/' },
              { text: 'Bootstrap', link: '/' },
              { text: 'AUI', link: '/' },
              { text: 'Amaze UI', link: '/' },
            ]
          },
        ],
      },
      // {
      //   text: '了解更多',
      //   ariaLabel: 'Language Menu',
      //   items: [
      //     { text: '项目', items: [
      //         { text: 'aa', link: 'https://aa' },
      //         { text: '测试-mobile', link: 'http://aa' },
      //       ]
      //     },
      //     { text: '其他', items: [
      //         { text: 'bb', link: 'http://bbb' },
      //         { text: 'bb', link: 'https://bbb' },
      //       ]
      //     }
      //   ],
      // },
      // { text: '更新记录', link: '/update/' },
    ],

    // 下面是方法，可以动态更新 侧边栏
    sidebar: vuePressSlide.config(),
  },

  // 开发环境 - 热更新
  // 指定 dev server 的端口。-> https://vuepress.vuejs.org/zh/config/#port
  port: 8081,
  // dest: ''
}

